<?php
session_start();
set_include_path('./../../nearestCaches/library' . PATH_SEPARATOR . get_include_path());
$PEAR_PATH = 'PEAR.php';
include ('Request/Request.php');
include "functions.php";
$lang = getLang();
$versionInt = getClientIntVersion();

if((!isset($_SESSION['cookie']))&&(
        (!isset($_POST['login'])&&!isset($_POST['password']))
        &&(!isset($_SERVER['PHP_AUTH_USER'])&&!isset($_SERVER['PHP_AUTH_PW']))
    )) {
    $_SESSION['latitude'] = $_POST['latitude'];
    $_SESSION['longitude'] = $_POST['longitude'];
    $_SESSION['finds'] = $_POST['finds'];
    //if user isn't authorized we send him authorization form
    if($versionInt && $versionInt < 90) {
        header('HTTP/1.1 401 Unauthorized');
    } else {
        header('WWW-Authenticate: Basic realm="Geocaching.com"');
        header('HTTP/1.0 401 Unauthorized');
    }
} else {
    if($versionInt && $versionInt < 90) {
        $login = $_POST['login'];
        $password = $_POST['password'];
    } else {
        $login = $_SERVER['PHP_AUTH_USER'];
        $password = $_SERVER['PHP_AUTH_PW'];
    }

    //login to geocaching.com (see functions.php)
    if(isset($login)&&isset($password))
    {
        login($login, $password);
    }


echo '<?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html>
              <head>
                <title>'.$lang['search_type'].'</title>
	</head>
	<body class="list"><ul>
		<li><a href="'.SERVICE_URL.'first.php" class="firstScreen">'.$lang['nearest_caches'].'</a></li>
		<li><a href="'.SERVICE_URL.'keyword.php" class="firstScreen">'.$lang['keyword_search'].'</a></li>
		<li><a href="'.SERVICE_URL.'waypoint.php" class="firstScreen">'.$lang['waypoint_search'].'</a></li>
	</body>
</html>';
}
?>
